-
Notifications
You must be signed in to change notification settings - Fork 1.7k
chore(ai): Add integration tests for Live API #15396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend splitting off the unit tests into a separate PR. They LGTM.
@andrewheard Oh I already intended to do this (see the PR description for reference). I just have everything here for my own centralization purposes, until I split them off. |
import SwiftUI | ||
import Testing | ||
|
||
@testable import struct FirebaseAI.APIConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice making tightly scoped testable imports 👍
|
||
@Suite(.serialized) | ||
struct LiveSessionTests { | ||
private let OneSecondInNanoseconds = UInt64(1e+9) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use lower camelcase for properties
private let OneSecondInNanoseconds = UInt64(1e+9) | |
private let oneSecondInNanoseconds = UInt64(1e+9) |
outputAudioTranscription: AudioTranscriptionConfig() | ||
) | ||
|
||
private enum systemInstructions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use upper camelcase for enum type definitions
private enum systemInstructions { | |
private enum SystemInstructions { |
return | ||
} | ||
await session.sendAudioRealtime(audioFile.data) | ||
await session.sendAudioRealtime(Data(repeating: 0, count: audioFile.data.count)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of doing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is received as silence to make the session end?
await session.sendTextRealtime("Alex") | ||
|
||
guard let toolCall = try await session.collectNextToolCall() else { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be preceded with an issue recording?
Something like–
return | |
Issue.record("Incomplete tool call.") | |
return |
|
||
#expect(functionCall.name == "getLastName") | ||
guard let response = getLastName(args: functionCall.args) else { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be preceded with an issue recording?
Something like–
return | |
Issue.record("Incomplete tool call.") | |
return |
await session.sendTextRealtime("Alex") | ||
|
||
guard let toolCall = try await session.collectNextToolCall() else { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like above, does this need an issue recording before the return?
await session.sendAudioRealtime(Data(repeating: 0, count: audioFile.data.count)) | ||
|
||
// wait a second to allow the model to start generating (and cuase a proper interruption) | ||
try await Task.sleep(nanoseconds: OneSecondInNanoseconds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try await Task.sleep(nanoseconds: OneSecondInNanoseconds) | |
try await Task.sleep(nanoseconds: oneSecondInNanoseconds) |
This PR adds Integration tests for the Live API.
The tests currently test the following:
Test are written via the swift testing framework (matching our other [newer] integration tests), and are parametrized to run across both backends and different services. I've removed the global variants of the parameters though, as the vertex model only supports
us-central1
anyhow.#no-changelog